/*
	YoghurtGum - 2D Game Engine

	Copyright 2009-2010 Quinten Lansu
	
	Licensed under the Apache License, Version 2.0 (the "License"); you may not 
	use this file except in compliance with the License. You may obtain a copy 
	of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
	License for the specific language governing permissions and limitations 
	under the License. 
*/

#ifndef _RENDERMETHODDIRECT3D_H_
#define _RENDERMETHODDIRECT3D_H_

#include "..\..\..\YoghurtGum\src\YGRenderMethod.h"

#include "ErrorDirect3D.h"

namespace YoghurtGum
{

	#define D3DMFVF_CUSTOMVERTEX (D3DMFVF_XYZ_FLOAT | D3DMFVF_DIFFUSE | D3DMFVF_TEX1)
	
	struct Vertex
	{
		FLOAT x, y, z;
		DWORD color;
		float tu, tv;
	};
	
	class RenderMethodDirect3D : public RenderMethod
	{

	public:

		enum
		{
			OPTION_TOSURFACE = 0,
			OPTION_TOTEXTURE = 1,
			OPTION_BACKBUFFER = 2
		};

		RenderMethod& GetSingleton();

		bool Init();
		void CleanUp();

		bool Clear();
		bool PreRender();
		bool PostRender();

		Surface* GetRenderTarget() { return m_D3DBackSurf; }

		void* GetObject() { return (void*)m_D3DObject; }
		void* GetDevice() { return (void*)m_D3DDevice; }

		void* GetPool() { return (void*)&m_D3DPool; }

		void SetClearColor(YGC a_Color);
		void SetFullScreen();

	private:

		RenderMethodDirect3D() : RenderMethod() { }
		~RenderMethodDirect3D() { }

		static RenderMethod*          s_Instance;

		int                           m_RenderMode;

		LPDIRECT3DMOBILE              m_D3DObject;
		LPDIRECT3DMOBILEDEVICE        m_D3DDevice;
		LPDIRECT3DMOBILEVERTEXBUFFER  m_D3DBuffer;
		LPDIRECT3DMOBILESURFACE       m_D3DOldTarget;

		LPDIRECT3DMOBILESURFACE       m_D3DRenderSurface;
		LPDIRECT3DMOBILETEXTURE       m_D3DRenderTexture;

		LPDIRECT3DMOBILESURFACE       m_D3DBack;
		D3DMMATRIX                    m_D3DOldRenderMatrix;

		Surface*                      m_D3DFrontSurf;
		Surface*                      m_D3DBackSurf;
		D3DMDISPLAYMODE               m_D3DMode;
		D3DMPRESENT_PARAMETERS        m_D3DOptions;
		D3DMCOLOR                     m_D3DClear;
		D3DMCAPS                      m_D3DCaps;
		D3DMPOOL                      m_D3DPool;
	
	}; // class RenderMethodDirect3D

}; // namespace YoghurtGum

#endif